package com.atguigu.spzx.manager.service.impl;

import com.atguigu.spzx.manager.mapper.SysUserRoleMapper;
import com.atguigu.spzx.manager.service.SysUserRoleService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class SysUserRoleServiceImpl implements SysUserRoleService {
    @Resource
    SysUserRoleMapper sysUserRoleMapper;
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void assignRoles2User(Long userId, List<Long> roleIds) {
        //删除userId所有的角色: sys_user_role中间表不存储真实数据 使用物理删除
        sysUserRoleMapper.deleteRolesByUserId(userId);
        //分配角色： 分配的角色中包含新增的 和之前已有的
        sysUserRoleMapper.assignRoles2User(userId,roleIds);
    }
}
